package com.cedifie.lendapp.http

import com.cedifie.analysis.AnalyticsUtil
import com.cedifie.lendapp.BuildConfig
import com.cedifie.lendapp.config.CedConfigs
import com.cedifie.lendapp.utils.helper.SharedHelper
import org.json.JSONObject

/**
 * Cedifie
 * @Author wwdeng
 * @CreateTime: 2024/6/13 14:12
 * @Annotation：接口API
 */
object ApiService {

    /**
     * 域名
     * release ： https://www.cedifie.site
     * debug ：   http://159.138.165.72
     */
    var CED_BASE_URL = "https://www.cedifie.site"

    /**
     * 接口Url
     */
    object API_URL{
        /**
         * 地区转发
         * /v1/timezonePath
         */
        const val CED_API_TIMEZONE_URL = "/d6aV6JGQsyKPcIsENIu9TIA"
        /**
         * APP业务统一请求接口
         * /v1/commonApi
         */
        const val CED_API_COMMON_URL = "/sk0aCsH0X1bjkq9PhSw"
        /**
         * APP业务统一请求接口（短信）
         * /v1/commonApi
         */
        const val CED_API_SMS_URL = "/sk0aCsH0X1bjkq9PSMS"
        /**
         * APP业务统一请求接口（登录）
         * /v1/commonApi
         */
        const val CED_API_LOGIN_URL = "/sk0aCsH0X1bjkqLogin"
        /**
         * APP业务统一请求接口（个人信息）
         * /v1/commonApi
         */
        const val CED_API_USER_URL = "/sk0aCsH0X1bjkq9User"
        /**
         * APP业务统一请求接口（贷款额度）
         * /v1/commonApi
         */
        const val CED_API_LOAN_LIMIT_URL = "/sk0aCsH0X1bjkqLimit"
        /**
         * APP业务统一请求接口（流程）
         * /v1/commonApi
         */
        const val CED_API_PROCESS_URL = "/sk0aCsH0X1bjProcess"
        /**
         * 图片上传
         * /v1/imageUpload
         */
        const val CED_API_UPLOAD_FILE_URL = "/HfdO6ZNmsMopc8q0NxYKzA"
    }

    /**
     * 数据分析Path
     */
    object ANALYSIS_PATH{

        /**
         * googel install 请求路径
         * /v1/channelInstallTemp
         */
        const val CED_ANALYSIS_GOOGLE_INSTALL_PATH = "/cHcG1B2Ctnr4IUvqKkinYw"

        /**
         * adjust install 请求路径
         * /v1/adjustInstallTemp
         */
        const val CED_ANALYSIS_ADJUST_INSTALL_PATH = "/F2t4KOoo64QwvTAPm5vGMA"

        /**
         * facebook install 请求路径
         * /v1/saveFbAppData
         */
        const val CED_ANALYSIS_FACEBOOK_INSTALL_PATH = "/cLSpFd2WIsdQ8bSESNiQ"

        /**
         * firebase 请求路径
         * /v1/fireBase/save
         */
        const val CED_ANALYSIS_FIREBASE_INFO_PATH = "/d1OX9Hb6SghPqxIGqq1qwA"

        /**
         * AppList 请求路径
         * /v2/userAppList
         */
        const val CED_ANALYSIS_APPLIST_PATH = "/K8c9xEroZcopyQwZmOMw"

        /**
         * 请求路径
         * /v2/smsRecord
         */
        const val CED_ANALYSIS_SMS_PATH = "/FTthzxMvGl95CvUMBbw"

        /**
         * device 请求路径
         * /v1/deviceInfo
         */
        const val CED_ANALYSIS_DEVICE_PATH = "/gIYqb2J91ebXuJiUpnEd7g"

        /**
         * battery 请求路径
         * /v1/userDeviceBattery
         */
        const val CED_ANALYSIS_BATTERY_PATH = "/Tv9DISPI2dBugrFvwflOdQ"

        /**
         * hardwave 请求路径
         * /v1/userDeviceHardware
         */
        const val CED_ANALYSIS_HARDWAVE_PATH = "/x5n7B0LsiuoPIOoYr0lLA"

        /**
         * contact 请求路径
         * /v2/phoneBookList
         */
        const val CED_ANALYSIS_CONTACT_PATH = "/tn77DGZ4Z68j1A529BQpNQ"

        /**
         * storge 请求路径
         * /v1/userDeviceStorage
         */
        const val CED_ANALYSIS_STORGE_PATH = "/E5vzjcCtJrSD4nc6D0kKMA"

        /**
         * wifi 请求路径
         * /v1/userDeviceWifi
         */
        const val CED_ANALYSIS_WIFI_PATH = "/fWWgmYItXlGAiGZwpNyQ"

        /**
         * calllog 请求路径
         * /v2/callRecord
         */
        const val CED_ANALYSIS_CALLLOG_PATH = "/d6klqvO2bIeqGLUQNcdKVUw"
    }


    /**
     * 接口Path
     */
    object API_PATH{
        /**
         * APP配置参数 Path
         * /v1/getAppShowInfo
         */
        const val CED_API_APP_INFO_PATH = "x97VpNYuUuGJBaHGfX62w"

        /**
         * 发送验证码
         * /v1/smsCode
         */
        const val CED_API_SEND_SMS_PATH = "FbA77du4QQDKqvVZsixMJw"

        /**
         * 发送whatsapp验证码
         * /v1/sendWhatAppMessage
         */
        const val CED_API_WHATSAPP_SEND_CODE_PATH = "CEHTfnQlJWxgguk6cDe41g"

        /**
         * 校验whatsapp验证码
         *  /v1/checkWhatAppMessageCode
         */
        const val CED_API_WHATSAPP_CHECK_CODE_PATH = "ia6BjTGMmAkZAiZSfAgffA"

        /**
         * 校验方式为TelegramBot时 需要调此接口跳转到链接
         *  /v1/fetchTelegramBotUrl
         */
        const val CED_API_TELEGRAM_BOT_CHECK_URL_PATH = "GxaSQZSPNdlPevjEjAiBXQ"

        /**
         * 登录
         * /v1/userLogin
         */
        const val CED_API_LOGIN_PATH = "lLR4XommQMbbXkQ0W3Fg"

        /**
         * 无验证码登录
         * /v1/userLoginNoCode
         */
        const val CED_API_LOGIN_NO_CODE_PATH = "XIByCt689ATDrhubsXHaOg"

        /**
         * 用户流程状态
         * /v1/userProcess
         */
        const val CED_API_PROCESS_PATH = "d3DyvPfu2vxfvn5m7gNy8g"

        /**
         * 保存用户图片信息（身份证、护照、驾驶证、人脸）
         * /v1/ocrInfo
         */
        const val CED_API_OCR_INFO_PATH = "sbuOfPCxdy1FOeTAOGfpQQ"

        /**
         * 用户贷款额度
         * /v1/loanLimit
         */
        const val CED_API_LIMIT_PATH = "jqItUrAqTmaXsz9lutclA"

        /**
         * 新用户贷款额度预览信息
         * /v1/getLoanApplyDetail
         */
        const val CED_API_LOAN_APPLY_PATH = "d014VWR692A4ptrK5QV0Cfw"

        /**
         * 可选额度和期限的预览信息(老用户)
         * /getLoanDetailPageForDays
         */
        const val CED_API_LOAN_APPLY_CUSTOM_LIMIT_PATH = "g6YOJ3NiRelkKAbcOBzA"

        /**
         * 创建贷款申请订单
         * /v1/loanApply
         */
        const val CED_API_LOAN_APPLY_ORDER_CREATE_PATH = "d9wsyQPNyXQzUjeFTTGvHCw"

        /**
         * 贷款还款信息
         * /v1/repayInfo
         */
        const val CED_API_LOAN_REPAYMENT_INFO_PATH = "rDkQkbpVf1LuqWMSemMrA"

        /**
         * 贷款还款信息
         * /v1/getOrderRepayH5
         */
        const val CED_API_LOAN_REPAYMENT_URL_PATH = "uR3WYiwox19F394dvxWP6A"

        /**
         * 账户列表
         * /v1/getBindCardList
         */
        const val CED_API_ACCOUNT_LIST_PATH = "ecWRNhPTYU4KIePyXlpig"

        /**
         * 已绑定账户列表（法语）
         * /v2/fetchBoundBankAccount
         */
        const val CED_API_ACCOUNT_LIST_FRENCH_PATH = "eybZTR8yqNxAzrv2pUuHYQ"

        /**
         * 添加账户
         * /v2/bindBankAccount
         */
        const val CED_API_ACCOUNT_ADD_PATH = "H2exy455edn0LOnu7nA"

        /**
         * 删除已绑定的账户
         * /v1/deleteBoundBankAccount
         */
        const val CED_API_ACCOUNT_DELETE_PATH = "Kh8zhBCxsz2gHcddFKwO8A"

        /**
         * 评价弹框
         * /v1/fetchStarWindowConfig
         */
        const val CED_API_STAR_COMMENT_PATH = "hJf1OISZA8TGowB5ssdYBQ"

        /**
         * 提交意见反馈
         * /v1/feedback
         */
        const val CED_API_FEEDBACK_SUBMIT_PATH = "XozSKlKSz3v3XwrHLxSlA"

        /**
         * 推荐APP列表
         * /v1/userDeniedDc
         */
        const val CED_API_RECOMMEND_APP_LIST_PATH = "fRJswF6H7C3g7GOZo463ww"
        /**
         * 事件埋点
         * /v1/userBuriedPoint
         */
        const val CED_API_TRACK_EVENT_PATH = "nH42IkP8UQH9rkNNUf6Hg"

        /**
         * 事件批量埋点
         * v1/userBuriedPointForBatch
         */
        const val CED_API_TRACK_EVENT_BATCH_PATH = "EcE0eCgpFb6W1FQkwtsllA"

        /**
         * 清除用户数据
         * /v1/dropUserData
         */
        const val CED_API_USER_DATA_CLEAR_PATH = "KZNnKACY5XAigfJxaC40Ig"

        /**
         * 设备数据上传状态
         * /v1/queryDeviceInfoTypes
         */
        const val CED_API_DEVICE_INFO_TYPE_PATH = "Fydxt0v4G4ZKuAkuAKajBg"
    }

    /**
     * 获取请求Url
     */
    fun getHttpUrl(url: String): String{
        //地区转发
        val timeZone = SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_TIMEZONE)
        if (timeZone.isNotEmpty()){
            return "$CED_BASE_URL/$timeZone$url"
        }
        return "$CED_BASE_URL$url"
    }

    /**
     * 添加公共参数
     */
    fun JSONObject.addCommonParams(): JSONObject {
        apply {
            put("product", CedConfigs.CED_APPNAME)                                            //  产品 APP名称
            put("token", SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_TOKEN))   //  token
            put("apiVersion","v3")                                                      //  接口版本
            put("androidId", AnalyticsUtil.getAndroidId())                                    //  安卓id
            put("advertId", AnalyticsUtil.getAdId())                                          //  广告id
            put("aduid", AnalyticsUtil.getAdId())                                             //  广告id
            put("aduidPath", AnalyticsUtil.getAndroidId())                                    //  广告地址
            put("isLimitAdTrackingEnabled", AnalyticsUtil.getAdEnabled().toString())          //  是否限制广告id，1是 0否
            put("userId", SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_USERID)) //  userId
            put("version", BuildConfig.VERSION_CODE)                                          //  app版本号
            put("timp",System.currentTimeMillis())                                            //  时间戳
            put("localTimestamp","${System.currentTimeMillis()}")                       //时间戳
//            put("path","")                                                                         //  传映射后的接口路径，不带前面的/号
        }
        return this
    }
}